path = "1.txt"
r = open(path,"r",encoding="utf-8")
#print(r.read())
print(r.readline())  #括号内读取多少个字符
print(r.readlines()) #返回数组,假如上面读取的字符后面不会再读取
r.close()

#使用with的时候不用额外关闭资源操作
with  open(path)  as   f:
    f.readlines()


# 'a'是追加的意思
with open(r'1.txt','a',encoding='gbk') as f1:
    f1.write('32345674123456789')
    # 刷新，提高写入的效率
    f1.flush()

# 'w'会覆盖写入原文件
with open(r'1.txt','w',encoding='gbk') as f2:
    f2.write('32345674123456789')
    # 刷新，提高写入的效率
    f2.flush()

# 二进制读取视频\图片等
with open(r'R-C.jpg','rb') as f1:
    r = f1.read()
    print(r)
with open(r'R-C.jpg','wb') as f2:
     f2.write(r)   # f2.write(字节)
     f2.flush()
